"""
快速排序算法
采用D&C（divide and conquer）方法求解
时间复杂度：调用栈层级*每层处理的数量=O(n)*O(logn)=O(nlogn)
"""


def quicksort(array):
    if len(array) < 2:
        return array
    else:
        pivot = array[0]
        less = [i for i in array[1:] if i <= pivot]
        greater = [i for i in array[1:] if i > pivot]
        # 合并子数组
        return quicksort(less) + [pivot] + quicksort(greater)


print(quicksort([10, 5, 2, 3]))
